<?php
/**
 * Created by PhpStorm.
 * User: 长春
 * Date: 2016/9/26
 * Time: 0:33
 */
class LoginAction extends Action{

    //登录接口
    public function login(){
        if (!IS_POST){
            halt('error');
        }else{
            $username = I('username');
            $passwd = I('passwd');
            $userInfo = M('user')->where(array('username' => $username))->find();
            $returnData = array();
            if (empty($userInfo)){
                $returnData['success'] = 0;
                $returnData['msg'] = '用户不存在';
            }else{
                if ($userInfo['passwd'] != $passwd){
                    $returnData['success'] = 0;
                    $returnData['msg'] = '密码错误，请重新输入。';
                }else{      //登录成功
                    session('username', $userInfo['username']);
                    session('userEmail', $userInfo['email']);
                    session('userPhone', $userInfo['phone']);
                    session('userid', $userInfo['id']);
                    $returnData['success'] = 1;
                    $returnData['msg'] = '登录成功';
                    $returnData['url'] = U('GROUP_NAME' . '/Blog/Index');
                }
            }

        }
    }
}